package com.isunland.managesystem.ui;

import android.os.Bundle;
import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.DepartmentContent;
import java.util.ArrayList;
import java.util.HashMap;

public class DeptChooseDialogFragment extends BaseNetworkDialogFragment {
  private CurrentUser mUser;

  @Override public void onCreate(Bundle savedInstanceState) {
    mUser = CurrentUser.newInstance(getActivity());
    super.onCreate(savedInstanceState);
  }

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<CustomerDialog>();
    DepartmentContent[] contents = new Gson().fromJson(arg0, DepartmentContent[].class);
    //将数组转化为集合
    ArrayList<DepartmentContent> dataList = new ArrayList<DepartmentContent>();
    for (int i = 0; i < contents.length; i++) {
      dataList.add(contents[i]);
    }

    if (dataList == null || dataList.size() == 0) {

      return null;
    }
    for (int i = 0; i < dataList.size(); i++) {
      list.add(new CustomerDialog(dataList.get(i).getOrgName(), dataList.get(i).getOrgCode()));
    }
    return list;
  }

  @Override public String getUrl() {

    return ApiConst.ULR_DEPT_LIST;
  }

  @Override public HashMap<String, String> getparameters() {
    HashMap<String, String> params = new HashMap<String, String>();
    params.put("memberCode", mUser.getMemberCode());
    params.put("isPaging", "0");
    params.put("style", "tree");
    params.put("postKindCodes", "'positionType01'");
    params.put("orderField", "porg_code,order_no");
    params.put("orderSeq", "asc");
    params.put("staffCode", mUser.getJobNumber());
    return params;
  }
}
